<template>
  <div>
    <tableComponents
      :isHavePagination="false"
      :isShow="false"
      :isHaveExport="false"
      @toAdd="checkBd(true)"
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list"
          v-loading="loading"
          stripe
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.9%"
        >
          <el-table-column
            type="selection"
            class="tc"
            width="35"
          ></el-table-column>

          <el-table-column
            prop="picture"
            header-align="center"
            align="center"
            width="200px"
            label="图片"
          >
            <template slot-scope="scope">
              <el-popover placement="right" title trigger="hover">
                <img
                  :src="$fnc.getImgUrl(scope.row.piclink)"
                  style="width: 500px"
                />
                <img
                  slot="reference"
                  :src="$fnc.getImgUrl(scope.row.piclink)"
                  style="width: 100px"
                />
              </el-popover>
            </template>
          </el-table-column>

          <el-table-column label="表名称" min-width="80">
            <template slot-scope="scope">{{ scope.row.title }}</template>
          </el-table-column>

          <el-table-column label="英文标识" min-width="80">
            <template slot-scope="scope">{{ scope.row.iden }}</template>
          </el-table-column>

          <el-table-column label="类型" min-width="80">
            <template slot-scope="scope">{{
              scope.row.types == 1 ? "选项类表单" : "填写类表单"
            }}</template>
          </el-table-column>

          <el-table-column prop="name" label="是否开启" min-width="80">
            <template slot-scope="scope">
              <el-switch
                class="zdySwith"
                :width="82"
                v-model="scope.row.is_open"
                active-color="#1aad19"
                inactive-color="#ffffff"
                active-text="开启"
                inactive-text="关闭"
                active-value="1"
                @change="getOpen($event, scope.row)"
                inactive-value="0"
              ></el-switch>
            </template>
          </el-table-column>

          <!-- <el-table-column prop="name" label="是否付费" min-width="80">
          <template slot-scope="scope">
            <el-switch
              class="zdySwith"
              :width="82"
              v-model="scope.row.is_pay"
              active-color="#1aad19"
              inactive-color="#ffffff"
              active-text="付费"
              inactive-text="免费"
              active-value="1"
              @change="getPay($event,scope.row)"
              inactive-value="0"
            ></el-switch>
          </template>
          </el-table-column>-->

          <el-table-column label="价格" min-width="80">
            <template slot-scope="scope">
              {{ scope.row.price | keepTwoNum }}元
              <div class="tab_div">
                <div>
                  <span>价格：</span>
                  <span>{{ scope.row.price | keepTwoNum }}</span>
                </div>
                <div>
                  <span>成本价格：</span>
                  <span>{{ scope.row.cost_price | keepTwoNum }}</span>
                </div>
                <div>
                  <span>备注：</span>
                  <span>{{ scope.row.remark }}</span>
                </div>
                <div>
                  <span>友情提醒：</span>
                  <span>{{ scope.row.help }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="时间" min-width="100">
            <template slot-scope="scope">{{
              scope.row.created_time | getTimeFormat
            }}</template>
          </el-table-column>

          <el-table-column label="操作" align="center" min-width="120">
            <template slot-scope="scope">
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                type="primary"
                @click="openDetails1(scope.row.id)"
                >查看</el-button
              >
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                type="primary"
                v-if="scope.row.types == 0"
                @click="openDetails(scope.row.id)"
                >到字段管理</el-button
              >
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                type="danger"
                @click="checkBd(false, scope.row)"
                >编辑</el-button
              >
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                type="success"
                @click="
                  $fnc.copyVal(
                    `${$store.state.phoneAddress}/pages/sub/form/form?id=${scope.row.id}`
                  )
                "
                >复制链接</el-button
              >
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                @click="deleteNew(scope.$index, scope.row.id)"
                type="danger"
                v-if="scope.row.iden !='supplier' && scope.row.iden !='agent' && scope.row.iden !='cooperation'"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog
      :close-on-click-modal="false"
      title="自定义表单"
      class="tl size_13"
      :append-to-body="true"
      :visible.sync="showBdFrom"
      width="800px"
    >
      <bd-form v-if="showBdFrom" @hideDio="getHideDio" :row="row" />
    </el-dialog>
  </div>
</template>
<script>
import HeadTitle from "@/components/currency/HeadTitle.vue";
import bdForm from "./bd-form";
export default {
  data() {
    return {
      list: [],
      loading: true,
      showBdFrom: false,
      row: {},
    };
  },
  components: {
    HeadTitle,
    bdForm,
  },
  methods: {
    openDetails(id) {
      let routeData = this.$router.resolve({
        path: "/index/form/bd-field-list",
        query: { id: id },
      });
      window.open(routeData.href, "_blank");
    },
    openDetails1(id) {
      this.$store.commit("addbreadcrumbs", {
        title: "查看详情",
        url: `/index/form/bd-msg?id=${id}&page=1`,
      });
      this.$router.push({
        path: "/index/form/bd-msg",
        query: { id: id, page: 1 },
      });
      // window.open(routeData.href, "_blank");
    },
    getHideDio(bool) {
      this.showBdFrom = false;
      if (bool) {
        this.getNewsAll();
      }
    },
    checkBd(bool, row) {
      if (bool) {
        this.row = {};
      } else {
        this.row = JSON.parse(JSON.stringify(row));
        if (this.row.sel_str) {
          this.row.sel_str = JSON.parse(this.row.sel_str);
        }else{
          this.row.sel_str = []
        }
      }
      this.showBdFrom = true;
    },
    getOpen(val, row) {
      var params = {};
      params = row;
      params.is_open = val;
      this.updata(params);
    },
    getPay(val, row) {
      var params = {};
      params = row;
      params.is_pay = val;
      this.updata(params);
    },
    updata(row, bool) {
      var params = {};
      params = row;
      this.$api.getForm.saveeditBd(params).then((res) => {
        if (res.data.status == 1 && res.data.code == 200) {
          if (bool) {
            this.$message.success("提交成功");
          }
          //  this.$message.success('提交成功');
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    getNewsAll() {
      this.$api.getForm.getBdList().then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
          this.$store.commit("setPluginForm", res.data.result);
        }
        this.loading = false;
      });
    },
    deleteNew(index, id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          var data = { id: id };
          this.$api.getForm.delBd(data).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.list.splice(index, 1);
            } else {
              this.$swal("删除失败！", res.data.result, "success");
            }
          });
        }
      });
    },
  },

  created() {
    this.getNewsAll();
  },
  computed: {},
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
</style>
